#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#

Import('BuildEnv')
import platform
import os

env = BuildEnv.Clone()

env.CppDisableExceptions()

env.Append(CPPPATH = [env['TOP'],
                      env['TOP'] + '/bgp',
                      env['TOP'] + '/db',
                      env['TOP'] + '/io',
                      env['TOP'] + '/tools/sandesh/library/common',
                      env['TOP'] + '/xmpp'
                     ])
env.Append(LIBPATH = ['#/' + Dir('..').path,
                      '../../bgp/inet',
                      '../../bgp/ermvpn',
                      '../../bgp/mvpn',
                      '../../bgp/evpn',
                      '../../bgp/inet6',
                      '../../bgp/inet6vpn',
                      '../../bgp/l3vpn',
                      '../../control-node',
                      '../../db',
                      '../../ifmap',
                      '../../net',
                      '../extended-community',
                      '../origin-vn',
                      '../rtarget',
                      '../routing-instance',
                      '../routing-policy',
                      '../../route',
                      '../security_group',
                      '../tunnel_encap',
                      '../../xmpp',
                      '../../schema',
                      '../../xml',
                      '.'
                     ])

libbgptest = env.Library('bgptest',
                         ['bgp_server_test_util.cc',
                          'bgp_test_util.cc'])

env.Alias('src/bgp:libbgptest', libbgptest)

libbgp_test_factory = env.Library(
    'bgp_test_factory',
    ['bgp_config_mock.cc'])

env.Append(LIBPATH = env['TOP'] + '/schema')
env.Append(LIBPATH = env['TOP'] + '/base/test')
env.Append(LIBPATH = env['TOP'] + '/db/test')
env.Append(LIBPATH = env['TOP'] + '/ifmap/test')
env.Append(LIBPATH = env['TOP'] + '/base')
env.Append(LIBPATH = env['TOP'] + '/control-node/test')

etcd_incl = os.environ.get('CONTRAIL_ETCD_INCL');

if etcd_incl:
    env.Prepend(LIBS = ['etcdql', 'protobuf', 'grpc++', 'grpc', 'z'])

env.Prepend(LIBS = ['control_test',
                    'bgptest',
                    'bgp',
                    'bgp_ifmap_config',
                    'bgp_xmpp',
                    'control_node', 'dbtest', 'ifmap_vnc', 'bgp_schema', 'task_test',
                    'ifmap_test_util', 'ifmap_test_util_server',
                    'ifmap_server', 'ifmap_common',
                    'ifmapio', 'ifmap_server', 'config_client_mgr', 'curl',
                    'peer_sandesh', 'sandesh', 'http', 'http_parser',
                    'xmpp', 'pugixml', 'xml',
                    'db', 'sandeshvns', 'process_info',
                    'io', 'crypto', 'ssl', 'base', 'gunit'])

if platform.system() == 'Darwin':
    bgp_inet = Dir('../inet').path + '/libbgp_inet.a'
    bgp_ermvpn = Dir('../ermvpn').path + '/libbgp_ermvpn.a'
    bgp_mvpn = Dir('../mvpn').path + '/libbgp_mvpn.a'
    bgp_evpn = Dir('../evpn').path + '/libbgp_evpn.a'
    bgp_l3vpn = Dir('../l3vpn').path + '/libbgp_l3vpn.a'
    bgp_rtarget = Dir('../rtarget').path + '/librtarget.a'
    bgp_inet6 = Dir('../inet6').path + '/libbgp_inet6.a'
    bgp_inet6vpn = Dir('../inet6vpn').path + '/libbgp_inet6vpn.a'
    env.Prepend(LINKFLAGS =
                ['-Wl,-force_load,' + bgp_inet,
                 '-Wl,-force_load,' + bgp_ermvpn,
                 '-Wl,-force_load,' + bgp_mvpn,
                 '-Wl,-force_load,' + bgp_evpn,
                 '-Wl,-force_load,' + bgp_l3vpn,
                 '-Wl,-force_load,' + bgp_inet6,
                 '-Wl,-force_load,' + bgp_inet6vpn,
                 '-Wl,-force_load,' + bgp_rtarget])
else:
    env.Prepend(LINKFLAGS =
                ['-Wl,--whole-archive',
                 '-rdynamic',
                 '-lbase',
                 '-lboost_filesystem',
                 '-lbgp_inet',
                 '-lbgp_ermvpn',
                 '-lbgp_mvpn',
                 '-lbgp_evpn',
                 '-lbgp_l3vpn',
                 '-lrtarget',
                 '-lbgp_inet6',
                 '-lbgp_inet6vpn',
                 '-lbgp_test_factory',
                 '-Wl,--no-whole-archive'])

env.Append(LIBS = [
    'bgp_ermvpn',
    'bgp_mvpn',
    'bgp_evpn',
    'bgp_inet',
    'bgp_inet6',
    'bgp_inet6vpn',
    'bgp_l3vpn',
    'bgp_test_factory',
    'rtarget',
    'control_node_uve',
    'io',
    'cassandra_cql',
    'SimpleAmqpClient',
    'rabbitmq',
    'cassandra',
    'gendb',
])

env.Append(LIBS = ['route', 'routing_instance', 'routing_policy', 'net'])

env.Append(LIBS = ['extended_community', 'origin_vn', 'security_group', 'tunnel_encap'])
env.Append(LIBS = ['xmpp_unicast', 'xmpp_multicast', 'xmpp_mvpn', 'xmpp_enet',
                   'boost_regex', 'boost_program_options', 'boost_chrono'])

if platform.system() != 'Darwin':
    env.Append(LIBS=['rt'])

except_env = env.Clone()
except_env.CppEnableExceptions()

config_test_env = env.Clone()
config_test_env.Append(LIBPATH = ['../../ifmap/test'])
config_test_env.Prepend(LIBS = ['ifmap_test_util'])

bgp_attr_test = env.UnitTest('bgp_attr_test',
                            ['bgp_attr_test.cc'])
env.Alias('src/bgp:bgp_attr_test', bgp_attr_test)

bgp_authentication_test = env.UnitTest('bgp_authentication_test',
                                       ['bgp_authentication_test.cc'])
env.Alias('src/bgp:bgp_authentication_test', bgp_authentication_test)

bgp_bgpaas_test = env.UnitTest('bgp_bgpaas_test', ['bgp_bgpaas_test.cc'])
env.Alias('src/bgp:bgp_bgpaas_test', bgp_bgpaas_test)

bgp_dscp_test = env.UnitTest('bgp_dscp_test', ['bgp_dscp_test.cc'])
env.Alias('src/bgp:bgp_dscp_test', bgp_dscp_test)

bgp_condition_listener_test = env.UnitTest('bgp_condition_listener_test',
                                     ['bgp_condition_listener_test.cc'])
env.Alias('src/bgp:bgp_condition_listener_test', bgp_condition_listener_test)

bgp_config_listener_test = config_test_env.UnitTest('bgp_config_listener_test',
                                                    ['bgp_config_listener_test.cc'])
env.Alias('src/bgp:bgp_config_listener_test', bgp_config_listener_test)

bgp_ifmap_config_manager_test = config_test_env.UnitTest(
    'bgp_ifmap_config_manager_test',
    ['bgp_ifmap_config_manager_test.cc'])
env.Alias('src/bgp:bgp_ifmap_config_manager_test',
          bgp_ifmap_config_manager_test)

bgp_config_test = config_test_env.UnitTest('bgp_config_test',
                                           ['bgp_config_test.cc'])
env.Alias('src/bgp:bgp_config_test', bgp_config_test)

bgp_evpn_aliasing_test = env.UnitTest('bgp_evpn_aliasing_test',
                                      ['bgp_evpn_aliasing_test.cc'])
env.Alias('src/bgp:bgp_evpn_aliasing_test', bgp_evpn_aliasing_test)

bgp_evpn_manager_test = env.UnitTest('bgp_evpn_manager_test',
                                     ['bgp_evpn_manager_test.cc'])
env.Alias('src/bgp:bgp_evpn_manager_test', bgp_evpn_manager_test)

bgp_evpn_test = env.UnitTest('bgp_evpn_test',
                             ['bgp_evpn_test.cc'])
env.Alias('src/bgp:bgp_evpn_test', bgp_evpn_test)

bgp_evpn_integration_test = env.UnitTest('bgp_evpn_integration_test',
                               ['bgp_evpn_integration_test.cc'])
env.Alias('src/bgp:bgp_evpn_integration_test', bgp_evpn_integration_test)

bgp_export_nostate_test = env.UnitTest('bgp_export_nostate_test',
                                       ['bgp_export_nostate_test.cc'])
env.Alias('src/bgp:bgp_export_nostate_test', bgp_export_nostate_test)

bgp_export_rstate_test = env.UnitTest('bgp_export_rstate_test',
                                      ['bgp_export_rstate_test.cc'])
env.Alias('src/bgp:bgp_export_rstate_test', bgp_export_rstate_test)

bgp_export_rtupdate_test = env.UnitTest('bgp_export_rtupdate_test',
                                        ['bgp_export_rtupdate_test.cc'])
env.Alias('src/bgp:bgp_export_rtupdate_test', bgp_export_rtupdate_test)

bgp_export_uplist_test = env.UnitTest('bgp_export_uplist_test',
                                      ['bgp_export_uplist_test.cc'])
env.Alias('src/bgp:bgp_export_uplist_test', bgp_export_uplist_test)

bgp_ip_test = env.UnitTest('bgp_ip_test',
                           ['bgp_ip_test.cc'])
env.Alias('src/bgp:bgp_ip_test', bgp_ip_test)

bgp_ip_test1 = env.UnitTest('bgp_ip_test1',
                            ['bgp_ip_test1.cc'])
env.Alias('src/bgp:bgp_ip_test1', bgp_ip_test1)

bgp_ip_test2 = env.UnitTest('bgp_ip_test2',
                            ['bgp_ip_test2.cc'])
env.Alias('src/bgp:bgp_ip_test2', bgp_ip_test2)

bgp_membership_test = env.UnitTest('bgp_membership_test',
                                   ['bgp_membership_test.cc'])
env.Alias('src/bgp:bgp_membership_test', bgp_membership_test)

bgp_msg_builder_test = env.UnitTest('bgp_msg_builder_test',
                                   ['bgp_msg_builder_test.cc'])
env.Alias('src/bgp:bgp_msg_builder_test', bgp_msg_builder_test)

bgp_multicast_test = env.UnitTest('bgp_multicast_test',
                                  ['bgp_multicast_test.cc'])
env.Alias('src/bgp:bgp_multicast_test', bgp_multicast_test)

bgp_mvpn_integration_test = env.UnitTest('bgp_mvpn_integration_test',
                               ['bgp_mvpn_integration_test.cc'])
env.Alias('src/bgp:bgp_mvpn_integration_test', bgp_mvpn_integration_test)

bgp_peer_close_gr_test = except_env.UnitTest('bgp_peer_close_gr_test',
                                          ['bgp_peer_close_gr_test.cc'])
env.Alias('src/bgp:bgp_peer_close_gr_test', bgp_peer_close_gr_test)

bgp_peer_close_test = except_env.UnitTest('bgp_peer_close_test',
                                          ['bgp_peer_close_test.cc'])
env.Alias('src/bgp:bgp_peer_close_test', bgp_peer_close_test)

peer_close_manager_test = except_env.UnitTest('peer_close_manager_test', ['peer_close_manager_test.cc'])
env.Alias('src/bgp:peer_close_manager_test', peer_close_manager_test)

bgp_peer_test = env.UnitTest('bgp_peer_test',
                            ['bgp_peer_test.cc'])
env.Alias('src/bgp:bgp_peer_test', bgp_peer_test)

bgp_proto_test = env.UnitTest('bgp_proto_test',
                            ['bgp_proto_test.cc'])
env.Alias('src/bgp:bgp_proto_test', bgp_proto_test)

bgp_ribout_updates_test = env.UnitTest('bgp_ribout_updates_test',
                                       ['bgp_ribout_updates_test.cc'])
env.Alias('src/bgp:bgp_ribout_updates_test', bgp_ribout_updates_test)

bgp_route_test = env.UnitTest('bgp_route_test',
                             ['bgp_route_test.cc'])
env.Alias('src/bgp:bgp_route_test', bgp_route_test)

bgp_server_test = env.UnitTest('bgp_server_test',
                               ['bgp_server_test.cc'])
env.Alias('src/bgp:bgp_server_test', bgp_server_test)

bgp_session_test = env.UnitTest('bgp_session_test',
                               ['bgp_session_test.cc'])
env.Alias('src/bgp:bgp_session_test', bgp_session_test)

bgp_show_evpn_table_test = env.UnitTest('bgp_show_evpn_table_test',
                                        ['bgp_show_evpn_table_test.cc'])
env.Alias('src/bgp:bgp_show_evpn_table_test', bgp_show_evpn_table_test)

bgp_show_instance_config_test = env.UnitTest('bgp_show_instance_config_test',
                                           ['bgp_show_instance_config_test.cc'])
env.Alias('src/bgp:bgp_show_instance_config_test',
           bgp_show_instance_config_test)

bgp_show_multicast_manager_test = env.UnitTest(
    'bgp_show_multicast_manager_test', ['bgp_show_multicast_manager_test.cc'])
env.Alias('src/bgp:bgp_show_multicast_manager_test',
          bgp_show_multicast_manager_test)

bgp_show_mvpn_manager_test = env.UnitTest(
    'bgp_show_mvpn_manager_test', ['bgp_show_mvpn_manager_test.cc'])
env.Alias('src/bgp:bgp_show_mvpn_manager_test', bgp_show_mvpn_manager_test)

bgp_show_mvpn_project_manager_test = env.UnitTest(
    'bgp_show_mvpn_project_manager_test',
    ['bgp_show_mvpn_project_manager_test.cc'])
env.Alias('src/bgp:bgp_show_mvpn_project_manager_test',
          bgp_show_mvpn_project_manager_test)

bgp_show_neighbor_test = env.UnitTest('bgp_show_neighbor_test',
                                      ['bgp_show_neighbor_test.cc'])
env.Alias('src/bgp:bgp_show_neighbor_test', bgp_show_neighbor_test)

bgp_show_route_summary_test = env.UnitTest('bgp_show_route_summary_test',
                                           ['bgp_show_route_summary_test.cc'])
env.Alias('src/bgp:bgp_show_route_summary_test', bgp_show_route_summary_test)

bgp_show_routing_instance_test = env.UnitTest('bgp_show_routing_instance_test',
    ['bgp_show_routing_instance_test.cc'])
env.Alias('src/bgp:bgp_show_routing_instance_test', bgp_show_routing_instance_test)

bgp_show_rtarget_group_test = env.UnitTest('bgp_show_rtarget_group_test',
                                           ['bgp_show_rtarget_group_test.cc'])
env.Alias('src/bgp:bgp_show_rtarget_group_test', bgp_show_rtarget_group_test)

bgp_stress_test = env.UnitTest('bgp_stress_test', ['bgp_stress_test.cc'])
env.Alias('src/bgp:bgp_stress_test', bgp_stress_test)

bgp_table_export_test = env.UnitTest('bgp_table_export_test',
                                     ['bgp_table_export_test.cc'])
env.Alias('src/bgp:bgp_table_export_test', bgp_table_export_test)

bgp_table_test = env.UnitTest('bgp_table_test', ['bgp_table_test.cc'])
env.Alias('src/bgp:bgp_table_test', bgp_table_test)

bgp_table_walk_test = env.UnitTest('bgp_table_walk_test', ['bgp_table_walk_test.cc'])
env.Alias('src/bgp:bgp_table_walk_test', bgp_table_walk_test)

bgp_update_rx_test = env.UnitTest('bgp_update_rx_test', ['bgp_update_rx_test.cc'])
env.Alias('src/bgp:bgp_update_rx_test', bgp_update_rx_test)

bgp_update_test = env.UnitTest('bgp_update_test',
                                 ['bgp_update_test.cc'])
env.Alias('src/bgp:bgp_update_test', bgp_update_test)

bgp_update_sender_test = env.UnitTest('bgp_update_sender_test',
                                      ['bgp_update_sender_test.cc'])
env.Alias('src/bgp:bgp_update_sender_test', bgp_update_sender_test)

bgp_xmpp_basic_test = env.UnitTest('bgp_xmpp_basic_test',
                                   ['bgp_xmpp_basic_test.cc'])
env.Alias('src/bgp:bgp_xmpp_basic_test', bgp_xmpp_basic_test)

bgp_xmpp_dscp_test = env.UnitTest('bgp_xmpp_dscp_test',
                                   ['bgp_xmpp_dscp_test.cc'])
env.Alias('src/bgp:bgp_xmpp_dscp_test', bgp_xmpp_dscp_test)

bgp_xmpp_channel_test = env.UnitTest('bgp_xmpp_channel_test',
                                     ['bgp_xmpp_channel_test.cc'])
env.Alias('src/bgp:bgp_xmpp_channel_test', bgp_xmpp_channel_test)

bgp_xmpp_deferq_test = env.UnitTest('bgp_xmpp_deferq_test',
                             ['bgp_xmpp_deferq_test.cc'])
env.Alias('src/bgp:bgp_xmpp_deferq_test', bgp_xmpp_deferq_test)

bgp_xmpp_labeledinet_test = env.UnitTest('bgp_xmpp_labeledinet_test',
                                     ['bgp_xmpp_labeledinet_test.cc'])
env.Alias('src/bgp:bgp_xmpp_labeledinet_test', bgp_xmpp_labeledinet_test)

bgp_xmpp_inetvpn_test = env.UnitTest('bgp_xmpp_inetvpn_test',
                                     ['bgp_xmpp_inetvpn_test.cc'])
env.Alias('src/bgp:bgp_xmpp_inetvpn_test', bgp_xmpp_inetvpn_test)

bgp_xmpp_inet6vpn_test = env.UnitTest('bgp_xmpp_inet6vpn_test',
                                      ['bgp_xmpp_inet6vpn_test.cc'])
env.Alias('src/bgp:bgp_xmpp_inet6vpn_test', bgp_xmpp_inet6vpn_test)

bgp_xmpp_ip_test = env.UnitTest('bgp_xmpp_ip_test',
                                ['bgp_xmpp_ip_test.cc'])
env.Alias('src/bgp:bgp_xmpp_ip_test', bgp_xmpp_ip_test)

bgp_xmpp_evpn_mcast_test = env.UnitTest('bgp_xmpp_evpn_mcast_test',
                                        ['bgp_xmpp_evpn_mcast_test.cc'])
env.Alias('src/bgp:bgp_xmpp_evpn_mcast_test', bgp_xmpp_evpn_mcast_test)

bgp_xmpp_evpn_test = env.UnitTest('bgp_xmpp_evpn_test',
                                  ['bgp_xmpp_evpn_test.cc'])
env.Alias('src/bgp:bgp_xmpp_evpn_test', bgp_xmpp_evpn_test)

bgp_xmpp_mcast_test = env.UnitTest('bgp_xmpp_mcast_test',
                                   ['bgp_xmpp_mcast_test.cc'])
env.Alias('src/bgp:bgp_xmpp_mcast_test', bgp_xmpp_mcast_test)

bgp_xmpp_mvpn_test = env.UnitTest('bgp_xmpp_mvpn_test',
                                   ['bgp_xmpp_mvpn_test.cc'])
env.Alias('src/bgp:bgp_xmpp_mvpn_test', bgp_xmpp_mvpn_test)

bgp_xmpp_parse_test = env.UnitTest('bgp_xmpp_parse_test',
                                   ['bgp_xmpp_parse_test.cc'])
env.Alias('src/bgp:bgp_xmpp_parse_test', bgp_xmpp_parse_test)

bgp_xmpp_rtarget_test = env.UnitTest('bgp_xmpp_rtarget_test', 
                                     ['bgp_xmpp_rtarget_test.cc'])
env.Alias('src/bgp:bgp_xmpp_rtarget_test', bgp_xmpp_rtarget_test)

bgp_subcluster_integration_test = env.UnitTest(
    'bgp_subcluster_integration_test', ['bgp_subcluster_integration_test.cc'])
env.Alias('src/bgp:bgp_subcluster_integration_test',
          bgp_subcluster_integration_test)

bgp_xmpp_test = env.UnitTest('bgp_xmpp_test',
                             ['bgp_xmpp_test.cc'])
env.Alias('src/bgp:bgp_xmpp_test', bgp_xmpp_test)

bgp_xmpp_wready_test = env.UnitTest('bgp_xmpp_wready_test',
                             ['bgp_xmpp_wready_test.cc'])
env.Alias('src/bgp:bgp_xmpp_wready_test', bgp_xmpp_wready_test)

graceful_restart_tests = [ ]
graceful_restart_flaky_tests = [ ]
for i in range(1, 12):
    gr_test = except_env.UnitTest("graceful_restart_flap_all_test" + str(i),
        ["graceful_restart_flap_all_test" + str(i) + ".cc"])
    env.Alias("src/bgp:graceful_restart_flap_all_test" + str(i), gr_test)
    if i < 8:
        graceful_restart_flaky_tests.append(gr_test)
    else:
        graceful_restart_tests.append(gr_test)

for i in range(1, 11):
    gr_test = except_env.UnitTest("graceful_restart_flap_some_test" + str(i),
        ["graceful_restart_flap_some_test" + str(i) + ".cc"])
    env.Alias("src/bgp:graceful_restart_flap_some_test" + str(i), gr_test)
    if i == 2 or i == 3 or i == 8 or i == 9:
        graceful_restart_flaky_tests.append(gr_test)
    else:
        graceful_restart_tests.append(gr_test)

for i in range(1, 8):
    gr_test = except_env.UnitTest("graceful_restart_instance_config_test" +
                                  str(i),
        ["graceful_restart_instance_config_test" + str(i) + ".cc"])
    graceful_restart_tests.append(gr_test)
    env.Alias("src/bgp:graceful_restart_instance_config_test" + str(i), gr_test)

bgp_mvpn_tests = [ ]
for i in range(1, 17):
    bgp_mvpn_test = except_env.UnitTest("bgp_mvpn_test" + str(i),
        ["bgp_mvpn_test" + str(i) + ".cc"])
    bgp_mvpn_tests.append(bgp_mvpn_test)
    env.Alias("src/bgp:bgp_mvpn_test" + str(i), bgp_mvpn_test)

path_resolver_test = env.UnitTest('path_resolver_test',
                                  ['path_resolver_test.cc'])
env.Alias('src/bgp:path_resolver_test', path_resolver_test)

path_resolver_test1 = env.UnitTest('path_resolver_test1',
                                   ['path_resolver_test1.cc'])
env.Alias('src/bgp:path_resolver_test1', path_resolver_test1)

path_resolver_test2 = env.UnitTest('path_resolver_test2',
                                   ['path_resolver_test2.cc'])
env.Alias('src/bgp:path_resolver_test2', path_resolver_test2)

ribout_attributes_test = env.UnitTest('ribout_attributes_test',
                              ['ribout_attributes_test.cc'])
env.Alias('src/bgp:ribout_attributes_test', ribout_attributes_test)

routepath_replicator_random_test = env.UnitTest('routepath_replicator_random_test',
                              ['routepath_replicator_random_test.cc'])
env.Alias('src/bgp:routepath_replicator_random_test', routepath_replicator_random_test)

routepath_replicator_test = env.UnitTest('routepath_replicator_test',
                              ['routepath_replicator_test.cc'])
env.Alias('src/bgp:routepath_replicator_test', routepath_replicator_test)

routing_instance_mgr_test = env.UnitTest('routing_instance_mgr_test',
                                         ['routing_instance_mgr_test.cc'])
env.Alias('src/bgp:routing_instance_mgr_test', routing_instance_mgr_test)

routing_instance_mgr_tracebuf_size_test = env.UnitTest('routing_instance_mgr_tracebuf_size_test',
                                         ['routing_instance_mgr_tracebuf_size_test.cc'])
env.Alias('src/bgp:routing_instance_mgr_tracebuf_size_test', routing_instance_mgr_tracebuf_size_test)

routing_instance_mgr_tracebuf_threshold_test = env.UnitTest('routing_instance_mgr_tracebuf_threshold_test',
                                         ['routing_instance_mgr_tracebuf_threshold_test.cc'])
env.Alias('src/bgp:routing_instance_mgr_tracebuf_threshold_test', routing_instance_mgr_tracebuf_threshold_test)

routing_instance_test = env.UnitTest('routing_instance_test',
                                     ['routing_instance_test.cc'])
env.Alias('src/bgp:routing_instance_test', routing_instance_test)

routing_policy_action_test = env.UnitTest('routing_policy_action_test',
                                          ['routing_policy_action_test.cc'])
env.Alias('src/bgp:routing_policy_action_test', routing_policy_action_test)

routing_policy_match_test = env.UnitTest('routing_policy_match_test',
                                         ['routing_policy_match_test.cc'])
env.Alias('src/bgp:routing_policy_match_test', routing_policy_match_test)

routing_policy_test = env.UnitTest('routing_policy_test',
                              ['routing_policy_test.cc'])
env.Alias('src/bgp:routing_policy_test', routing_policy_test)

route_aggregator_test = env.UnitTest('route_aggregator_test',
                                     ['route_aggregator_test.cc'])
env.Alias('src/bgp:route_aggregator_test', route_aggregator_test)

rt_network_attr_test = env.UnitTest('rt_network_attr_test',
                                    ['rt_network_attr_test.cc'])
env.Alias('src/bgp:rt_network_attr_test', rt_network_attr_test)

bgp_xmpp_rtarget_manager_test = env.UnitTest('bgp_xmpp_rtarget_manager_test',
                                    ['bgp_xmpp_rtarget_manager_test.cc'])
env.Alias('src/bgp:bgp_xmpp_rtarget_manager_test',
          bgp_xmpp_rtarget_manager_test)

xmpp_message_builder_test = env.UnitTest('xmpp_message_builder_test', ['xmpp_message_builder_test.cc'])
env.Alias('src/bgp:xmpp_message_builder_test', xmpp_message_builder_test)

rt_unicast_test = env.UnitTest('rt_unicast_test',
                              ['rt_unicast_test.cc'])
env.Alias('src/bgp:rt_unicast_test', rt_unicast_test)

service_chain_test = env.UnitTest('service_chain_test',
                                     ['service_chain_test.cc'])
env.Alias('src/bgp:service_chain_test', service_chain_test)

service_chain_test1 = env.UnitTest('service_chain_test1',
                                     ['service_chain_test1.cc'])
env.Alias('src/bgp:service_chain_test1', service_chain_test1)

service_chain_test2 = env.UnitTest('service_chain_test2',
                                     ['service_chain_test2.cc'])
env.Alias('src/bgp:service_chain_test2', service_chain_test2)

service_chain_test3 = env.UnitTest('service_chain_test3',
                                     ['service_chain_test3.cc'])
env.Alias('src/bgp:service_chain_test3', service_chain_test3)

service_chain_test4 = env.UnitTest('service_chain_test4',
                                     ['service_chain_test4.cc'])
env.Alias('src/bgp:service_chain_test4', service_chain_test4)

svc_static_route_intergration_test1 = env.UnitTest('svc_static_route_intergration_test1',
                                     ['svc_static_route_intergration_test1.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test1', svc_static_route_intergration_test1)

svc_static_route_intergration_test1_1 = env.UnitTest('svc_static_route_intergration_test1_1',
                                     ['svc_static_route_intergration_test1_1.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test1_1', svc_static_route_intergration_test1_1)

svc_static_route_intergration_test1_2 = env.UnitTest('svc_static_route_intergration_test1_2',
                                     ['svc_static_route_intergration_test1_2.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test1_2', svc_static_route_intergration_test1_2)

svc_static_route_intergration_test1_3 = env.UnitTest('svc_static_route_intergration_test1_3',
                                     ['svc_static_route_intergration_test1_3.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test1_3', svc_static_route_intergration_test1_3)

svc_static_route_intergration_test1_4 = env.UnitTest('svc_static_route_intergration_test1_4',
                                     ['svc_static_route_intergration_test1_4.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test1_4', svc_static_route_intergration_test1_4)

svc_static_route_intergration_test1_5 = env.UnitTest('svc_static_route_intergration_test1_5',
                                     ['svc_static_route_intergration_test1_5.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test1_5', svc_static_route_intergration_test1_5)

svc_static_route_intergration_test1_6 = env.UnitTest('svc_static_route_intergration_test1_6',
                                     ['svc_static_route_intergration_test1_6.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test1_6', svc_static_route_intergration_test1_6)

svc_static_route_intergration_test1_7 = env.UnitTest('svc_static_route_intergration_test1_7',
                                     ['svc_static_route_intergration_test1_7.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test1_7', svc_static_route_intergration_test1_7)

svc_static_route_intergration_test1_8 = env.UnitTest('svc_static_route_intergration_test1_8',
                                     ['svc_static_route_intergration_test1_8.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test1_8', svc_static_route_intergration_test1_8)

svc_static_route_intergration_test2 = env.UnitTest('svc_static_route_intergration_test2',
                                     ['svc_static_route_intergration_test2.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test2', svc_static_route_intergration_test2)

svc_static_route_intergration_test2_1 = env.UnitTest('svc_static_route_intergration_test2_1',
                                     ['svc_static_route_intergration_test2_1.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test2_1', svc_static_route_intergration_test2_1)

svc_static_route_intergration_test2_2 = env.UnitTest('svc_static_route_intergration_test2_2',
                                     ['svc_static_route_intergration_test2_2.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test2_2', svc_static_route_intergration_test2_2)

svc_static_route_intergration_test2_3 = env.UnitTest('svc_static_route_intergration_test2_3',
                                     ['svc_static_route_intergration_test2_3.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test2_3', svc_static_route_intergration_test2_3)

svc_static_route_intergration_test2_4 = env.UnitTest('svc_static_route_intergration_test2_4',
                                     ['svc_static_route_intergration_test2_4.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test2_4', svc_static_route_intergration_test2_4)

svc_static_route_intergration_test3 = env.UnitTest('svc_static_route_intergration_test3',
                                     ['svc_static_route_intergration_test3.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test3', svc_static_route_intergration_test3)

svc_static_route_intergration_test3_1 = env.UnitTest('svc_static_route_intergration_test3_1',
                                     ['svc_static_route_intergration_test3_1.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test3_1', svc_static_route_intergration_test3_1)

svc_static_route_intergration_test3_2 = env.UnitTest('svc_static_route_intergration_test3_2',
                                     ['svc_static_route_intergration_test3_2.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test3_2', svc_static_route_intergration_test3_2)

svc_static_route_intergration_test3_3 = env.UnitTest('svc_static_route_intergration_test3_3',
                                     ['svc_static_route_intergration_test3_3.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test3_3', svc_static_route_intergration_test3_3)

svc_static_route_intergration_test3_4 = env.UnitTest('svc_static_route_intergration_test3_4',
                                     ['svc_static_route_intergration_test3_4.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test3_4', svc_static_route_intergration_test3_4)

svc_static_route_intergration_test4 = env.UnitTest('svc_static_route_intergration_test4',
                                     ['svc_static_route_intergration_test4.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test4', svc_static_route_intergration_test4)

svc_static_route_intergration_test4_1 = env.UnitTest('svc_static_route_intergration_test4_1',
                                     ['svc_static_route_intergration_test4_1.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test4_1', svc_static_route_intergration_test4_1)

svc_static_route_intergration_test4_2 = env.UnitTest('svc_static_route_intergration_test4_2',
                                     ['svc_static_route_intergration_test4_2.cc'])
env.Alias('src/bgp:svc_static_route_intergration_test4_2', svc_static_route_intergration_test4_2)

show_route_test = env.UnitTest('show_route_test',
                             ['show_route_test.cc'])
env.Alias('src/bgp:show_route_test', show_route_test)

state_machine_test = env.UnitTest('state_machine_test',
                                 ['state_machine_test.cc'])
env.Alias('src/bgp:state_machine_test', state_machine_test)

static_route_test = env.UnitTest('static_route_test',
                                 ['static_route_test.cc'])
env.Alias('src/bgp:static_route_test', static_route_test)

xmpp_sess_toggle_test = env.UnitTest('xmpp_sess_toggle_test',
                             ['xmpp_sess_toggle_test.cc'])
env.Alias('src/bgp:xmpp_sess_toggle_test', xmpp_sess_toggle_test)

# YAML based configuration
# Requires package libyaml-cpp-dev available on ubuntu 14.04+
yaml_test_env = env.Clone()
yaml_test_env.Append(LIBS = ['bgp_yaml_config',
                             'yaml-cpp'])
bgp_yaml_config_manager_test = yaml_test_env.UnitTest(
    'bgp_yaml_config_manager_test',
    ['bgp_yaml_config_manager_test.cc'])
yaml_test_env.Alias('bgp:bgp_yaml_config_manager_test',
                    bgp_yaml_config_manager_test)

# All Tests
test_suite = [
    bgp_attr_test,
    bgp_authentication_test,
    bgp_bgpaas_test,
    bgp_condition_listener_test,
    bgp_config_listener_test,
    bgp_dscp_test,
    bgp_ifmap_config_manager_test,
    bgp_config_test,
    bgp_evpn_aliasing_test,
    bgp_evpn_integration_test,
    bgp_evpn_manager_test,
    bgp_evpn_test,
    bgp_export_nostate_test,
    bgp_export_rstate_test,
    bgp_export_rtupdate_test,
    bgp_export_uplist_test,
    bgp_ip_test1,
    bgp_ip_test2,
    bgp_membership_test,
    bgp_msg_builder_test,
    bgp_multicast_test,
    bgp_mvpn_integration_test,
    bgp_peer_close_gr_test,
    bgp_peer_close_test,
    bgp_peer_test,
    bgp_proto_test,
    bgp_ribout_updates_test,
    bgp_route_test,
    bgp_server_test,
    bgp_session_test,
    bgp_show_evpn_table_test,
    bgp_show_instance_config_test,
    bgp_show_multicast_manager_test,
    bgp_show_mvpn_manager_test,
    bgp_show_mvpn_project_manager_test,
    bgp_show_neighbor_test,
    bgp_show_route_summary_test,
    bgp_show_routing_instance_test,
    bgp_show_rtarget_group_test,
    bgp_stress_test,
    bgp_subcluster_integration_test,
    bgp_table_export_test,
    bgp_table_test,
    bgp_table_walk_test,
    bgp_update_rx_test,
    bgp_update_test,
    bgp_update_sender_test,
    bgp_xmpp_basic_test,
    bgp_xmpp_dscp_test,
    bgp_xmpp_channel_test,
    bgp_xmpp_deferq_test,
    bgp_xmpp_evpn_mcast_test,
    bgp_xmpp_evpn_test,
    bgp_xmpp_inetvpn_test,
    bgp_xmpp_inet6vpn_test,
    bgp_xmpp_ip_test,
    bgp_xmpp_labeledinet_test,
    bgp_xmpp_mcast_test,
    bgp_xmpp_mvpn_test,
    bgp_xmpp_parse_test,
    bgp_xmpp_rtarget_test,
    bgp_xmpp_rtarget_manager_test,
    bgp_xmpp_test,
    bgp_xmpp_wready_test,
    path_resolver_test1,
    path_resolver_test2,
    peer_close_manager_test,
    ribout_attributes_test,
    route_aggregator_test,
    routepath_replicator_random_test,
    routepath_replicator_test,
    routing_instance_mgr_test,
    routing_instance_mgr_tracebuf_size_test,
    routing_instance_mgr_tracebuf_threshold_test,
    routing_instance_test,
    routing_policy_action_test,
    routing_policy_match_test,
    routing_policy_test,
#   rt_network_attr_test,
    service_chain_test1,
    service_chain_test2,
    service_chain_test3,
    service_chain_test4,
    show_route_test,
    state_machine_test,
    static_route_test,
    svc_static_route_intergration_test1_1,
    svc_static_route_intergration_test1_2,
    svc_static_route_intergration_test1_3,
    svc_static_route_intergration_test1_4,
    svc_static_route_intergration_test1_5,
    svc_static_route_intergration_test1_6,
    svc_static_route_intergration_test1_7,
    svc_static_route_intergration_test1_8,
    svc_static_route_intergration_test2_1,
    svc_static_route_intergration_test2_2,
    svc_static_route_intergration_test2_3,
    svc_static_route_intergration_test2_4,
    svc_static_route_intergration_test3_1,
    svc_static_route_intergration_test3_2,
    svc_static_route_intergration_test3_3,
    svc_static_route_intergration_test3_4,
    svc_static_route_intergration_test4_1,
    svc_static_route_intergration_test4_2,
    xmpp_message_builder_test,
    xmpp_sess_toggle_test,
]

env.Alias('src/bgp:graceful_restart_test', graceful_restart_tests)
test_suite += graceful_restart_tests

env.Alias('src/bgp:bgp_mvpn_test', bgp_mvpn_tests)
test_suite += bgp_mvpn_tests

test = env.TestSuite('bgp-test', test_suite)

env.Alias('controller/src/bgp:test', [
    test,
    'controller/src/bgp/ermvpn:test',
    'controller/src/bgp/mvpn:test',
    'controller/src/bgp/evpn:test',
    'controller/src/bgp/inet6:test',
    'controller/src/bgp/inet6vpn:test',
    'controller/src/bgp/l3vpn:test',
    'controller/src/bgp/origin-vn:test',
    'controller/src/bgp/rtarget:test',
    'controller/src/bgp/tunnel_encap:test',
])

flaky_test_suite = [
]
flaky_test_suite += graceful_restart_flaky_tests
flaky_test = env.TestSuite('bgp-flaky-test', flaky_test_suite)

env.Alias('controller/src/bgp:flaky-test', [
    flaky_test,
    'controller/src/bgp/l3vpn:flaky-test',
])

env.Alias('controller/src/bgp:all-test', [
    test,
    flaky_test,
    'controller/src/bgp/l3vpn:flaky-test',
])

# EVPN Related Tests
evpn_test_suite = [
    bgp_evpn_manager_test,
    bgp_xmpp_evpn_test,
    bgp_xmpp_evpn_mcast_test,
]

evpn_test = env.TestSuite('bgp-evpn-test', evpn_test_suite)
env.Alias('src/bgp:evpn_test', evpn_test)

#  Update Engine Tests
update_test_suite = [
    bgp_export_nostate_test,
    bgp_export_rstate_test,
    bgp_export_rtupdate_test,
    bgp_export_uplist_test,
    bgp_ribout_updates_test,
    bgp_update_sender_test,
    bgp_update_test,
]

update_test = env.TestSuite('bgp-update-test', update_test_suite)
env.Alias('src/bgp:update_test', update_test)

# Service Chain Related Tests
sc_test_suite = [
    bgp_condition_listener_test,
    bgp_xmpp_rtarget_test,
    routepath_replicator_random_test,
    routepath_replicator_test,
    service_chain_test1,
    service_chain_test2,
    service_chain_test3,
    service_chain_test4,
    static_route_test,
    svc_static_route_intergration_test1_1,
    svc_static_route_intergration_test1_2,
    svc_static_route_intergration_test1_3,
    svc_static_route_intergration_test1_4,
    svc_static_route_intergration_test1_5,
    svc_static_route_intergration_test1_6,
    svc_static_route_intergration_test1_7,
    svc_static_route_intergration_test1_8,
    svc_static_route_intergration_test2_1,
    svc_static_route_intergration_test2_2,
    svc_static_route_intergration_test2_3,
    svc_static_route_intergration_test2_4,
    svc_static_route_intergration_test3_1,
    svc_static_route_intergration_test3_2,
    svc_static_route_intergration_test3_3,
    svc_static_route_intergration_test3_4,
    svc_static_route_intergration_test4_1,
    svc_static_route_intergration_test4_2,
]

sc_test = env.TestSuite('bgp-sc-test', sc_test_suite)
env.Alias('src/bgp:sc_test', sc_test)

# Stress Tests
envs = env.Dictionary()["ENV"]
if 'BGP_STRESS_TEST_SUITE' in envs and envs['BGP_STRESS_TEST_SUITE'] != "0":
    env.Alias('src/bgp:bgp_stress_test_suite', env.TestSuite('bgp-stress-test',
              [
                  env.UnitTest('bgp_stress_test1', ['bgp_stress_test1.cc']),
                  env.UnitTest('bgp_stress_test2', ['bgp_stress_test2.cc']),
                  env.UnitTest('bgp_stress_test3', ['bgp_stress_test3.cc']),
                  env.UnitTest('bgp_stress_test4', ['bgp_stress_test4.cc']),
                  env.UnitTest('bgp_stress_test5', ['bgp_stress_test5.cc']),
                  env.UnitTest('bgp_stress_test6', ['bgp_stress_test6.cc']),
                  env.UnitTest('bgp_stress_test7', ['bgp_stress_test7.cc']),
              ]))

Return('test_suite')

# Local Variables:
# mode: python
# End:
